package com.alangyun.remind.repository.mapping;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

public class DatasetHistory implements Serializable {

	@XStreamAlias("histories")
	private List<HistoryFile> filenames;

	public List<HistoryFile> getFilenames() {
		return filenames;
	}

	public void setFilenames(List<HistoryFile> filenames) {
		this.filenames = filenames;
	}

	public void insert(String filename, String origin) {
		if (filenames == null)
			filenames = new ArrayList<>();
		filenames.add(0, HistoryFile.create(origin, filename));
	}

	@XStreamAlias("history")
	public static class HistoryFile {
		@XStreamAlias("date")
		@XStreamAsAttribute
		private Date date;
		@XStreamAlias("origin")
		@XStreamAsAttribute
		private String primeName;
		@XStreamAlias("file")
		@XStreamAsAttribute
		private String fileName;

		public static HistoryFile create(String origin, String fileName) {
			HistoryFile ret = new HistoryFile();
			ret.date = new Date();
			ret.primeName = origin;
			ret.fileName = fileName;
			return ret;
		}

		public Date getDate() {
			return date;
		}

		public void setDate(Date date) {
			this.date = date;
		}

		public String getPrimeName() {
			return primeName;
		}

		public void setPrimeName(String primeName) {
			this.primeName = primeName;
		}

		public String getFileName() {
			return fileName;
		}

		public void setFileName(String fileName) {
			this.fileName = fileName;
		}

	}
}
